package com.vlyman.redis.config;

import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * 类描述：
 *  jedis配置类
 * @author chenjs
 * @date 2019/1/7 10:13
 **/
@Slf4j
public class JedisConfig {

    public static JedisPool redisPoolFactory(JedisPoolConfig config, String host,
            int port, int timeout, String password){
        try {
            JedisPool jedisPool = new JedisPool(config, host, port, timeout, password);
            jedisPool.getResource();
            log.info("初始化Redis连接池JedisPool成功!" + " Redis地址: " + host + ":" + port);
            return jedisPool;
        } catch (Exception e) {
            log.error("初始化Redis连接池JedisPool异常!", e);
        }
        return null;
    }

    public static JedisPool redisPoolFactory(JedisPoolConfig config, String host,
            int port, int timeout){
        try {
            JedisPool jedisPool = new JedisPool(config, host, port, timeout);
            jedisPool.getResource();
            log.info("初始化Redis连接池JedisPool成功!" + " Redis地址: " + host + ":" + port);
            return jedisPool;
        } catch (Exception e) {
            log.error("初始化Redis连接池JedisPool异常!", e);
        }
        return null;
    }
}
